package edu.stanford.prpl.impl;

import edu.stanford.prpl.api.Group;
import edu.stanford.prpl.api.Identity;
import edu.stanford.prpl.api.PRPLObjectManager;
import edu.stanford.prpl.api.PRPLObjectManager.IdentityManager;

public class IdentityImpl extends PRPLObjectImpl implements Identity {

	IdentityManager identityManager;

	String identityKey;
	String identityName;

	public IdentityImpl(String identityUri, PRPLObjectManager objManager) {
		super(identityUri, objManager);
		this.identityManager = objManager.getIdentityManager();
	}

	//@Override
	public Group[] getGroups() {
		return this.identityManager.getAllGroupsForIdentity(objectURI);
	}

	//@Override
	public String getKey() {
		if (this.identityKey == null)
			this.identityKey = this.identityManager.getIdentityKey(objectURI);
		return this.identityKey;
	}

	//@Override
	public String getName() {
		if (this.identityName == null)
			this.identityName = this.identityManager.getIdentityName(objectURI);
		return this.identityName;
	}

	//@Override
	public String getURI() {
		return this.objectURI;
	}

	//@Override
	public void setName(String name) {
		if (this.identityManager.setIdentityName(objectURI, name))
			this.identityName = name;
	}
}
